package com.ptl.bp.dto;

import com.ptl.bp.config.DataAccessEnum;
import com.ptl.bp.config.SensitiveData;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.net.URI;
import java.time.LocalDateTime;

/**
 * 电池通用产品信息实体类
 * 描述：包含产品标识、制造商信息、生产地点、生产日期、电池类别、电池重量、电池状态等必填数据
 */
@Data
@Schema(description = "必填数据：产品标识；制造商标识；生产地点；生产日期；电池类别；电池重量；电池状态（附件VI第A部分和附件XIII）")
public class BatteryGeneralProductInfo {

    // 电池类别枚举
    public enum BatteryCategory {
        @Schema(description = "轻型交通工具电池") lmt,
        @Schema(description = "电动汽车电池") ev,
        @Schema(description = "工业用电池") industrial,
        @Schema(description = "固定式电池") stationary
    }

    // 电池状态枚举
    public enum BatteryStatus {
        @Schema(description = "原始状态") Original,
        @Schema(description = "改用途") Repurposed,
        @Schema(description = "再利用") Reused,
        @Schema(description = "再制造") Remanufactured,
        @Schema(description = "废品") Waste
    }

    // 邮政地址信息
    @Data
    @Schema(description = "邮政地址信息")
    public static class PostalAddress {
        @NotBlank(message = "国家不能为空")
        @Schema(description = "国家", required = true)
        private String addressCountry;

        @NotBlank(message = "街道地址不能为空")
        @Schema(description = "街道地址", required = true)
        private String streetAddress;

        @NotBlank(message = "邮政编码不能为空")
        @Schema(description = "邮政编码", required = true)
        private String postalCode;

    }

    // 联系信息
    @Data
    @Schema(description = "联系信息")
    public static class ContactInfo {
        @NotBlank(message = "联系人姓名不能为空")
        @Schema(description = "联系人姓名", required = true)
        private String contactName;

        @NotNull(message = "邮政地址不能为空")
        @Schema(description = "邮政地址", required = true)
        private PostalAddress postalAddress;

        @NotBlank(message = "标识符不能为空")
        @Schema(description = "唯一标识符", required = true)
        private String identifier;

        @Pattern(regexp = "^[\\w.-]+@[\\w.-]+\\.[A-Za-z]{2,}$", message = "邮箱格式不正确")
        @Schema(description = "邮箱地址")
        private String emailAddress;

        @Schema(description = "网站地址", format = "uri")
        private String webAddress;
    }

    @NotBlank(message = "产品标识不能为空")
    @Schema(description = "允许明确识别每个单独电池及其相应电池护照的唯一标识符",required = true )
    private String productIdentifier;

    @Pattern(regexp = "^urn:[a-z0-9]+:[a-z0-9]+$", message = "URN格式不正确")
    @Schema(description = "允许明确识别每个单独电池及其相应电池护照的唯一标识符",required = true )
    private String batteryPassportIdentifier;

    @NotNull(message = "电池类别不能为空")
    @Schema(description = "与电池护照相关的类别：LMT电池、电动汽车电池、固定式或其他工业电池>2kWh",required = true )
    private BatteryCategory batteryCategory;

    @NotNull(message = "制造商信息不能为空")
    @Schema(description = "电池制造商的明确标识，建议通过唯一的操作者标识符",required = true )
    private ContactInfo manufacturerInformation;

    @SensitiveData(hasAnyRole = {DataAccessEnum.RIGHT})
    @NotNull(message = "投入使用日期不能为空")
    @Schema(description = "投入使用日期不仅应关联电池型号，还应关联电池项目。日期代码应符合DIN ISO 8601标准",
        required = true,  format = "date-time" , example = "2025-01-01 10:10:10"
    )
    private LocalDateTime manufacturingDate;

    @SensitiveData(hasAnyRole={DataAccessEnum.RIGHT})
    @NotNull(message = "电池状态不能为空")
    @Schema(description = "电池的生命周期状态。状态从列表中选择，建议选项为：'original', 'repurposed', 'reused', 'remanufactured', 'waste'",required = true )
    private BatteryStatus batteryStatus;

    @NotNull(message = "电池重量不能为空")
    @DecimalMin(value = "0", message = "电池重量不能为负数")
    @Schema(description = "整个电池的质量（千克）。可选：如果电池定义在包或模块级别：还包括模块和/或电池的重量",required = true )
    private Double batteryMass;

    @NotNull(message = "生产地点不能为空")
    @Schema(description = "生产设施的明确标识（例如国家、城市、街道、建筑物（如果需要）），建议通过唯一的设施标识符",required = true )
    private PostalAddress manufacturingPlace;

    @NotNull(message = "操作者信息不能为空")
    @Schema(description = "说明名称、商号或商标、邮政地址、网址、电子邮件地址。建议通过唯一的操作者标识符报告",required = true )
    private ContactInfo operatorInformation;

    @Pattern(
        regexp = "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?",
        message = "日期时间格式不正确"
    )
    @Schema(description = "在适当的情况下，电池护照必须包括电池投入使用日期的信息",required = true )
    private String puttingIntoService;

    @Pattern(
        regexp = "--(0[1-9]|1[0-2])(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?",
        message = "保修期格式不正确"
    )
    @Schema(description = "电池护照必须包括商业保修适用期限的信息",required = true )
    private String warrentyPeriod;
}